<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <script src="libs/layui/layui.js"></script>
        <link rel="stylesheet" href="libs/layui/css/layui.css" />
        <link rel="stylesheet" href="css/example.css" />
        <title>实名认证</title>
    </head>
    <body>
        <div class="board">
            <div class="board-title">实名认证</div>
            <div class="board-content">
                <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
                    <ul class="layui-tab-title">
                        <li class="layui-this">基本使用</li>
                        <li>常用场景</li>
                    </ul>
                    <div class="layui-tab-content">
                        <div class="layui-tab-item layui-show">
                            <div class="layui-elem-quote">默认方式, 直接初始化, 默认会自动更新对应 input 内的值, 但保存数据为 base64, 数据量较大, 不是特别友好. 点击提交审核后请在控制台查看效果</div>
                            <form class="layui-form" action="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">真实姓名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="name" required lay-verify="required" placeholder="请填写与身份证一致的真实姓名" autocomplete="off" class="layui-input" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">身份证照片</label>
                                    <div class="layui-input-inline" style="width: auto">
                                        <input type="text" name="sfz_zm" class="layui-input zhengmian1" />
                                    </div>
                                    <div class="layout-input-inline" style="width: auto">
                                        <input type="text" name="sfz_fm" class="layui-input fanmian1" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">手持身份证照片</label>
                                    <div class="layout-input-inline" style="width: auto">
                                        <input type="text" name="sfz_sc" class="layui-input shouchi1" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="tab1submit">提交审核</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="layui-tab-item">
                            <div class="layui-elem-quote">对于大多数的场景而言, 基本都是选择后调用上传接口获得图片地址, 你可以通过关闭 autoUpdate 来自行实现该逻辑</div>
                            <form class="layui-form" action="">
                                <div class="layui-form-item">
                                    <label class="layui-form-label">真实姓名</label>
                                    <div class="layui-input-block">
                                        <input type="text" name="name" required lay-verify="required" placeholder="请填写与身份证一致的真实姓名" autocomplete="off" class="layui-input" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">身份证照片</label>
                                    <div class="layui-input-inline" style="width: auto">
                                        <input type="text" name="sfz_zm" class="layui-input zhengmian2" />
                                    </div>
                                    <div class="layout-input-inline" style="width: auto">
                                        <input type="text" name="sfz_fm" class="layui-input fanmian2" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <label class="layui-form-label">手持身份证照片</label>
                                    <div class="layout-input-inline" style="width: auto">
                                        <input type="text" name="sfz_sc" class="layui-input shouchi2" />
                                    </div>
                                </div>
                                <div class="layui-form-item">
                                    <div class="layui-input-block">
                                        <button class="layui-btn" lay-submit lay-filter="tab2submit">提交审核</button>
                                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="layui-tab-item">3</div>
                    </div>
                </div>
            </div>
        </div>
        <script>
            layui
                .config({
                    base: "./libs/layui_exts/",
                })
                .extend({
                    idCardUpload: "idCardUpload/js/index",
                });

            layui.use(["idCardUpload", "form"], function () {
                var form = layui.form;
                var idCardUpload = layui.idCardUpload;

                // 以下代码对应着tab页面1
                idCardUpload.zhengmian(".zhengmian1");
                idCardUpload.fanmian(".fanmian1");
                idCardUpload.shouchi(".shouchi1");

                form.on("submit(tab1submit)", function (data) {
                    console.log("数据格式", data.field);
                    layer.open({
                        icon: 2,
                        title: "温馨提示",
                        content: "默认方式为Base64, 基本没多少实际场景会这么做, 你可以打开控制台查看表单数据",
                        area: ["320px", "auto"],
                    });
                    return false;
                });

                // 以下代码对应着tab页面2
                var option = {
                    // 关闭自动更新内容
                    autoUpdate: false,
                    event: {
                        // 监听选择文件
                        selectedFile: function(doms, file, next) {
                            layer.msg("假装在上传文件", {
                                icon: 16,
                                time: 1.5 * 1000,
                                end: function () {
                                    // 使用 next 渲染服务端返回的图片地址
                                    next("china.jpg");
                                },
                            });
                            return false;
                        },
                    },
                };

                idCardUpload.zhengmian(".zhengmian2", option);
                idCardUpload.fanmian(".fanmian2", option);
                idCardUpload.shouchi(".shouchi2", option);

                form.on("submit(tab2submit)", function (data) {
                    layer.open({
                        icon: 1,
                        title: "表单数据",
                        content: "<pre>" + JSON.stringify(data.field, null, 4) + "</pre>",
                        area: ["320px", "auto"],
                    });
                    return false;
                });
            });
        </script>
    </body>
</html>
